package edu.stanford.bmir.protege.web.client.ui.ontology.stkos.cutter.common.menuitem;

import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.gwtext.client.widgets.tree.TreeNode;

import edu.stanford.bmir.protege.web.client.project.Project;
import edu.stanford.bmir.protege.web.client.rpc.stkosutil.StkosUtilServiceManager;
import edu.stanford.bmir.protege.web.client.rpc.stkosutil.common.UtilEntityType;
import edu.stanford.bmir.protege.web.client.rpc.stkosutil.cutter.CuttingOptions;
import edu.stanford.bmir.protege.web.client.rpc.stkosutil.cutter.CuttingResult;
import edu.stanford.bmir.protege.web.client.ui.ontology.stkos.common.StkosPanelType;
import edu.stanford.bmir.protege.web.client.ui.ontology.stkos.common.contextMenu.AbstractStkosTreeNodeMenuItem;
import edu.stanford.bmir.protege.web.client.ui.ontology.stkos.common.treepanel.AbstractStkosTreePanel;
import edu.stanford.bmir.protege.web.shared.project.ProjectId;

public abstract class AbstractStkosCutterTreeNodeMenuItem extends
		AbstractStkosTreeNodeMenuItem {

	protected StkosPanelType type;

	protected TreeNode selectedTreeNode;
	protected Project project;
	protected AbstractStkosTreePanel treePanel;

	protected AbstractStkosCutterTreeNodeMenuItem(String text, String iconCls,
			boolean disabled) {
		super(text, iconCls, disabled);
	}

	public AbstractStkosCutterTreeNodeMenuItem(String text, String iconCls,
			boolean disabled, TreeNode selectedTreeNode, Project project,
			AbstractStkosTreePanel treePanel) {
		this(text, iconCls, disabled);
		checkNull(treePanel);
		checkNull(project);
		checkNull(project.getProjectId());
		checkNull(project.getProjectId().getId());
		checkNull(selectedTreeNode);
		checkNull(selectedTreeNode.getUserObject());
		this.selectedTreeNode = selectedTreeNode;
		this.project = project;
		this.treePanel = treePanel;
	}

	public AbstractStkosCutterTreeNodeMenuItem(String text, String iconCls,
			TreeNode selectedTreeNode, Project project,
			AbstractStkosTreePanel treePanel) {
		this(text, iconCls, false, selectedTreeNode, project, treePanel);
	}

	protected void refreshSelectedTreeNode() {
		treePanel.refreshTreeNode(selectedTreeNode);
	}

	public void updateAnnotaionValue(ProjectId projectId, String entityName,
			UtilEntityType entityType, String annotationName,
			String annotationValue, AsyncCallback<Void> callback) {
		checkNull(projectId);
		checkNull(entityName);
		checkNull(entityType);
		checkNull(annotationName);
		checkNull(annotationValue);
		StkosUtilServiceManager.getInstance().updateAnnotaionValue(projectId,
				entityName, entityType, annotationName, annotationValue,
				callback);
	}

	public void cutOntology(String projectName, CuttingOptions options,
			AsyncCallback<CuttingResult> callback) {
		checkNull(projectName);
		checkNull(options);
		StkosUtilServiceManager.getInstance().cutOntology(projectName, options,
				callback);
	}

	public void removeAnnotationValue(String projectName, String entityName,
			UtilEntityType entityType, String annotationName,
			String annotationValuePattern, AsyncCallback<Integer> callback) {
		checkNull(projectName);
		checkNull(entityName);
		checkNull(entityType);
		checkNull(annotationName);
		checkNull(annotationValuePattern);
		StkosUtilServiceManager.getInstance().removeAnnotationValue(
				projectName, entityName, entityType, annotationName,
				annotationValuePattern, callback);
	}
}
